## Project: Lario
## Module: MainMenu
## Author: Salwan

import pygame
import pyenkido.gui.gui_manager
import pyenkido.entity
import pyenkido.controller
import pyenkido.screen_effects
import pyenkido.image_utils
from lario.defs import *

# enum MainMenu Phases
MM_PHASE_1 = 1
MM_PHASE_2 = 2
MM_PHASE_3 = 3

class MainMenuScene(pyenkido.scene.Scene):
    def start(self):
        self.texture = pyenkido.image_utils.load_image("res/textures/", "intro.png")
        self.texture.set_colorkey((255, 0, 255))
        self.ticks = 0
        self.sceneMgr.add_screen_effect(pyenkido.screen_effects.FadeEffect(self.screen, (0, 0, 0), True, 0, 120))

        self.texGround = self.texture.subsurface(MainMenuData[TEX_MM_GROUND])
        self.texCurtain = self.texture.subsurface(MainMenuData[TEX_MM_CURTAIN])

        self.curtainHeight = 170
        self.curtainStartTime = 160

        self.phase2Time = 160

        self.phase = MM_PHASE_1

    def update(self):
        self.ticks += 1
        if self.phase == MM_PHASE_1:
            if self.ticks >= self.curtainStartTime:
                self.curtainHeight -= 1
        elif self.phase == MM_PHASE_2:
            self.phase2Time -= 1
            if self.phase2Time <= 0:
                self.phase = MM_PHASE_3

    def draw(self):
        self.screen.fill((0, 0, 0))
        self.screen.blit(self.texGround, (0, 192))

        if self.phase == MM_PHASE_1:
            if self.curtainHeight > -50:
                pygame.draw.rect(self.screen, (198, 8, 24), pygame.Rect(0, -10, 256, self.curtainHeight + 14))
                for i in range(0, 8):
                    for j in range(0, 12):
                        self.screen.blit(self.texCurtain, (i * 32, self.curtainHeight - (j * 16)))
            else:
                self.phase += 1
        elif self.phase == MM_PHASE_2:
            pass
        elif self.phase == MM_PHASE_3:
            self.screen.fill((255, 255, 0))
